
<template>
  <div class="cart-bottom-bar">
    <div class="price">
      <CheckButton @click.native='selectAll' :is-checked='isAllCheck' />
      <span class='select'>全选</span>
      <span>合计:{{totoalPrice}}</span>
    </div>
    <div class="total" @click="toBuyOrder">
      <span>去结算({{orderLen}})</span>
    </div>
  </div>
</template>

<script>
import CheckButton from 'components/content/cartcheck/cartbuttonbar.vue'
import { mapGetters } from 'vuex'
export default {
  name: 'cartbar',
  components: { CheckButton },

  data() {
    return {}
  },
  computed: {
    ...mapGetters(['carList', 'carListLength']),
    orderLen() {
      return this.carList.filter(v => v.check).length
    },
    isAllCheck() {
      if (this.carListLength === 0) {
        return false
      } else {
        return !this.carList.find(v => !v.check)
      }
    },
    totoalPrice() {
      let str = '￥'
      if (this.orderLen === 0) {
        str += 0
      } else {
        str += this.carList
          .filter(v => v.check)
          .reduce((sum, v) => {
            return sum + v.newPrice * v.count
          }, 0)
          .toFixed(2)
      }
      return str
    }
  },
  methods: {
    toBuyOrder() {
      if (!this.orderLen) {
        this.$toast.show('请选择山坡', 3000)
      }
    },

    selectAll() {
      let res = false
      if (this.isAllCheck) {
        res = false
      } else {
        res = true
      }
      this.$store.commit('editCartCheckAll', res)
    }
  }
}
</script>

<style scoped>
.cart-bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 49px;
  height: 44px;
  background-color: #eee;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
}
.price {
  display: flex;
  flex: auto;
  align-items: center;
  padding-left: 10px;
}
.select {
  margin: 0 15px 0 10px;
}
.total {
  line-height: 44px;
  text-align: center;
  width: 100px;
  background-color: orangered;
  color: #fff;
}
</style>
